﻿namespace Anley.DomainDrivenDesign.Contract.Helper;

/// <summary>
/// 图片帮助类
/// </summary>
public class ImageHelper
    : IImageHelper
{
    // 下载文件
    public async Task DownloadFileAsync(
        string remoteUrl,
        string localPath)
    {
        using var httpClient = new HttpClient();
        var httpResponse = await httpClient.GetAsync(remoteUrl);
        httpResponse.EnsureSuccessStatusCode();
        using var httpContent = await httpResponse.Content.ReadAsStreamAsync();
        httpContent.Seek(0, SeekOrigin.Begin);
        using var fileStream = File.Create(localPath);
        httpContent.CopyTo(fileStream);
        fileStream.Flush();
    }
}